<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use App\Constants\ErrorCode;
use App\Utils\ContextUtil;
use App\Utils\Helper;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Psr\Container\ContainerInterface;

abstract class AbstractController
{
    #[Inject]
    protected ContainerInterface $container;

    #[Inject]
    protected RequestInterface $request;

    #[Inject]
    protected ResponseInterface $response;

    public function getUser()
    {
        return ContextUtil::getUser();
    }

    public function getUserId()
    {
        return ContextUtil::getUserId();
    }

    public function getAdmin()
    {
        return ContextUtil::getAdmin();
    }

    public function getAdminId()
    {
        return ContextUtil::getAdminId();
    }

    public function success($data, $msg='OK', $extData=null)
    {
        return Helper::resp($this->response, ErrorCode::HTTP_OK, $msg, $data, $extData );
    }

    public function fail($msg='fail', $extData=null, $data=null)
    {
        return Helper::resp($this->response, ErrorCode::SERVICE_HAND_FAILED, $msg, $data, $extData );
    }

    public function allParams()
    {
        return Helper::trimParams($this->request->all());
    }
}
